﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IntelligentDecisioning.SharePoint.BusinessEntities;
using IntelligentDecisioning.SharePoint.Shared;
using Microsoft.SharePoint;
using IntelligentDecisioning.SharePoint.Helpers;
using IntelligentDecisioning.SharePoint.Definitions;

namespace IntelligentDecisioning.SharePoint.Repositories
{
    public class DemonstrationTaskRepository: IDemonstrationTaskRepository
    {
        public DemonstrationTaskRepository()
        {

        }


        #region IDemonstrationTaskRepository Members

        public List<DemonstrationTaskEntity> GetTasks(IDSharePointContext context)
        {
            using(SPSite targetSite = new SPSite(context.SiteCollectionUrl))
            {
                SPWeb targetWeb = null;

                if (context.UseRootWeb)
                {
                    targetWeb = targetSite.OpenWeb();
                }
                else
                {
                    targetWeb = targetSite.OpenWeb(context.WebRelativeURL);
                }

                // Delegate the work of loading the entities to the list class
                return new DemonstrationTaskList().GetTasks(targetWeb); 
            }
        }

        #endregion
    }
}
